package com.ky.serialport.sensor;

import android.util.Log;

import com.ky.serialport.bean.ComBean;
import com.ky.serialport.utils.MyFunc;

import static com.ky.serialport.utils.FormatUtils.df2;
import static com.ky.serialport.utils.RandomUtils.myRandom;

/**
 * 拉力传感器数据
 */
public class LaLiDataBean {
    public Long time = 0L;
    public String lali = 0.00 + ""; //这里用的第一个数值
    public Float[] laliArry = new Float[2];
    public int type = -1; // 0x40 20T   0x42  30T    0x43 手刹   0x44  踏板
    public int powerVel = 0; //电量
    public int assiVel = 0; //信号
    public int index = -1;
    public ComBean comBean;


    public LaLiDataBean() {

    }

    public LaLiDataBean(ComBean comBean ) {
        caculate(comBean.recData);
        this.comBean = comBean;
        time = comBean.recTime;
    }

    public LaLiDataBean(byte[] recData ) {
        caculate(recData);
        time = System.currentTimeMillis();
    }

    public LaLiDataBean caculate(ComBean comBean){
        time = comBean.recTime;
        return caculate(comBean.recData);
    }

    public LaLiDataBean caculate(byte[] buffer) {
        time = System.currentTimeMillis();
        powerVel = (int) (MyFunc.twoByte2IntNoSign(buffer[18], buffer[19]));
        assiVel = MyFunc.HexToInt(MyFunc.Byte2Hex(buffer[20]));
        type = buffer[9];
        index = buffer[10];
        Log.d("ceui12314566", "caculate: " + (df2 == null));
        laliArry[0] = MyFunc.twoBytes2IntSign(buffer[14], buffer[15])/100f;
        laliArry[1] = MyFunc.twoBytes2IntSign(buffer[16], buffer[17])/100f;
        lali = df2.format(laliArry[0]);
        return this;
    }

    public LaLiDataBean test() {
        time = System.currentTimeMillis();
        powerVel = 300 + myRandom.nextInt(120);
        assiVel = 200;
        lali = df2.format(10 + myRandom.nextFloat() * 100f);
        return this;
    }

}
